﻿using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Drawing;
using System;
namespace Server
{
    [Serializable]
    public class SocketPacket
    {
        public SocketPacket(System.Net.Sockets.Socket socket, int clientNumber)
        {
            m_currentSocket = socket;
            m_clientNumber = clientNumber;
        }
        [NonSerialized]
        public System.Net.Sockets.Socket m_currentSocket;
        [NonSerialized]
        public int m_clientNumber;

        [NonSerialized]
        public List<byte> TransmissionBuffer = new List<byte>();
        [NonSerialized]
        public byte[] dataBuffer = new byte[1024];

        public string message;
        public Color color;

        public byte[] Serialize()
        {
            BinaryFormatter bin = new BinaryFormatter();
            MemoryStream mem = new MemoryStream();
            bin.Serialize(mem, this);
            return mem.GetBuffer();
        }

        public SocketPacket DeSerialize()
        {
            byte[] _dataBuffer = TransmissionBuffer.ToArray();
            BinaryFormatter bin = new BinaryFormatter();
            MemoryStream mem = new MemoryStream();
            mem.Write(dataBuffer, 0, _dataBuffer.Length);
            mem.Seek(0, 0);
            return (SocketPacket)bin.Deserialize(mem);
        }
    }
}
